import 'package:aihu_getx_app/app/modules/commons/commons.dart';
import 'package:aihu_getx_app/app/modules/d/d_member/d_member_vipuser_index/widgets/vip_user_list_filter_drawer.dart';
import 'package:aihu_getx_app/app/modules/d/d_member/d_member_vipuser_index/widgets/vip_user_list_item_widget.dart';
import 'package:aihu_getx_app/utils/constants.dart';
import 'package:aihu_getx_app/utils/init_system_data_util.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/d_member_vipuser_index_controller.dart';

class DMemberVipuserIndexView extends GetView<DMemberVipuserIndexController> {
  const DMemberVipuserIndexView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: controller.scaffoldKey,
      appBar: Commons.appBar(
        title: controller.pageTitle.value,
        subTitle: controller.appName.value,
        refresh: controller.onRefresh,
        actions: [
          IconButton(
            onPressed: () {
              controller.scaffoldKey.currentState!.openEndDrawer();
            },
            icon: const Icon(Icons.search),
          ),
        ],
      ),
      endDrawer: const VipUserListFilterDrawer(),
      body: Obx(
        () => Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Divider(
              height: 1,
              thickness: 1,
            ),
            Container(
              height: 45,
              width: double.infinity,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.all(5),
              decoration: BoxDecoration(
                color: Get.theme.primaryColor,
              ),
              child: ListView(
                scrollDirection: Axis.horizontal,
                children: [
                  const Text(
                    "筛选条件:",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 20,
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.nickname)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(controller.searchForm.value.nickname ?? ''),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.nickname = '';
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(Icons.clear),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.status)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(null == controller.searchForm.value.status
                          ? ''
                          : InitSystemDataUtil.getDictLabelByTypeAndValue(
                              DictTypeEnum.commonStatus.type,
                              controller.searchForm.value.status)!),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.status = null;
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(
                        Icons.clear,
                      ),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.mobile)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(controller.searchForm.value.mobile ?? ''),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.mobile = '';
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(Icons.clear),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.registerIp)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(controller.searchForm.value.registerIp ?? ''),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.registerIp = '';
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(Icons.clear),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.loginIp)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(controller.searchForm.value.loginIp ?? ''),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.loginIp = '';
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(Icons.clear),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.loginDate)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(
                        GetUtils.isNullOrBlank(
                                controller.searchForm.value.loginDate)!
                            ? ""
                            : "${controller.searchForm.value.loginDate?[0].substring(0, 10)}~${controller.searchForm.value.loginDate?[1].substring(0, 10)}",
                      ),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.loginDate = null;
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(Icons.clear),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                  Offstage(
                    offstage: GetUtils.isNullOrBlank(
                        controller.searchForm.value.createTime)!,
                    child: Chip(
                      padding: const EdgeInsets.all(0),
                      label: Text(
                        GetUtils.isNullOrBlank(
                                controller.searchForm.value.createTime)!
                            ? ""
                            : "${controller.searchForm.value.createTime?[0].substring(0, 10)}~${controller.searchForm.value.createTime?[1].substring(0, 10)}",
                      ),
                      onDeleted: () {
                        controller.searchForm.update((searchForm) {
                          searchForm?.createTime = null;
                        });
                        controller.onRefresh();
                      },
                      deleteIcon: const Icon(Icons.clear),
                      deleteIconColor: Colors.white,
                      labelStyle:
                          const TextStyle(color: Colors.white, fontSize: 20),
                      backgroundColor: Get.theme.secondaryHeaderColor,
                    ),
                  ),
                ],
              ),
            ),
            // Container(
            //   height: 40,
            //   child: Text('filterBar'),
            // ),
            Expanded(
              child: RefreshIndicator(
                color: Get.theme.primaryColorLight,
                backgroundColor: Get.theme.primaryColor,
                onRefresh: controller.onRefresh,
                child: ListView.builder(
                  controller: controller.scrollController,
                  itemCount: controller.dataList.length + 1,
                  itemBuilder: (context, index) {
                    if (index == controller.dataList.length) {
                      return controller.buildProgressMoreIndicator();
                    }
                    return VipUserListItemWidget(controller.dataList[index]);
                  },
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
